package com.hbnu.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.dto.OpusAddDTO;
import com.hbnu.system.model.dto.SearchPageDTO;
import com.hbnu.system.model.dto.UserDTO;
import com.hbnu.system.model.entity.Opus;
import com.hbnu.system.service.IOpusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-05-16
 */
@RestController
@RequestMapping("/opus")
@Api(tags = "公开出版作品模块")
public class OpusController {

    @Autowired
    IOpusService iOpusService;

    @ApiOperation("作品-初次录入")
    @PostMapping("/addOpusDTO")
    public Rest<Boolean> addOpusDTO(@RequestBody OpusAddDTO opusAddDTO){
        boolean add = iOpusService.addOpus(opusAddDTO);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("作品-正式录入")
    @PostMapping("/addOpus")
    public Rest<Boolean> addOpus(@RequestBody Opus opus){
        boolean add = iOpusService.addOpus(opus);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("作品-删除")
    @GetMapping("/DeleteOpus")
    public Rest<Boolean> DeleteOpus(String opusID){
        boolean delete = iOpusService.deleteOpus(opusID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("作品-修改")
    @GetMapping("/UpdateOpus")
    public Rest<Boolean> UpdateOpus(Opus opus){
        boolean update = iOpusService.updateOpus(opus);
        return update ? Rest.success() : Rest.failed();
    }

    @ApiOperation("作品-提交")
    @GetMapping("/CommitOpus")
    public Rest<Boolean> CommitOpus(String opusID){
        Boolean commit = iOpusService.CommitOpus(opusID);
        return commit ? Rest.success() : Rest.failed();
    }

    @ApiOperation("根据主键作品查询")
    @GetMapping("/GetOpusById")
    public Rest<Opus> GetOpusById(String opusID){
        Opus opus = iOpusService.getOpus(opusID);
        return Rest.success(opus);
    }


    @ApiOperation("作品-分页查询")
    @PostMapping ("/pagecondition")
    public Rest<CommonPage<Opus>> pageProjectCondition(@RequestBody SearchPageDTO searchTaskDTO){
        IPage<Opus> page = iOpusService.pageCondition(searchTaskDTO);
        CommonPage<Opus> activityVOCommonPage = CommonPage.restPage(page);
        return Rest.success(activityVOCommonPage);
    }

    @ApiOperation("作品-校级通过")
    @GetMapping("/SchoolPassOpus")
    public Rest<String> SchoolPassOpus(@RequestHeader("X-Token") String token,String opusID){
        Boolean b = iOpusService.schoolCheckPass(token,opusID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("作品-校级退回")
    @PostMapping("/SchoolBackOpus")
    public Rest<String> SchoolBackOpus(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iOpusService.schoolCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("用户获取与自己相关的作品-分页")
    @PostMapping("/UserGetRelateOpus")
    public Rest<CommonPage<Opus>> UserGetRelateOpus(@RequestBody UserDTO userDTO){
        IPage<Opus> opusIPage = iOpusService.userGetRelateOpus(userDTO);
        CommonPage<Opus> opusCommonPage = CommonPage.restPage(opusIPage);
        return Rest.success(opusCommonPage);
    }


    @ApiOperation("校级管理员查看需要自己审核的作品-分页")
    @PostMapping("/SchoolUserGetOpus")
    public Rest<CommonPage<Opus>> SchoolUserGetOpus(@RequestBody UserDTO userDTO){
        IPage<Opus> opusIPage = iOpusService.schoolUserGetOpus(userDTO);
        CommonPage<Opus> opusCommonPage = CommonPage.restPage(opusIPage);
        return Rest.success(opusCommonPage);
    }

}

